<template>
  <div id="list">
    <ul>
      <li v-for="item in admins" :key="item.id" :class="{ active: currentSession ? item.username === currentSession.username : false }" v-on:click="changeCurrentSession(item)">
        <!--   :class="[item.id === currentSessionId ? 'active':'']" -->
        <!-- <el-badge is-dot> -->
        <img class="avatar" :src="item.userFace" :alt="item.name" />
        <p class="name">{{ item.name }}</p>
        <el-badge :is-dot="idDot[user.username + '#' + item.username]"></el-badge>
        <!-- </el-badge> -->
      </li>
    </ul>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'list',
  data() {
    return {
      user: JSON.parse(sessionStorage.getItem('user')),
    }
  },
  computed: mapState(['sessions', 'currentSession', 'admins', 'idDot']),
  methods: {
    changeCurrentSession(currentSession) {
      this.$store.commit('changeCurrentSession', currentSession)
    },
  },
}
</script>

<style lang="scss" scoped>
#list {
  li {
    position: relative;
    padding: 12px 15px;
    border-bottom: 1px solid #292c33;
    cursor: pointer;
    &:hover {
      background-color: rgba(255, 255, 255, 0.03);
    }
  }
  li.active {
    /*注意这个是.不是冒号:*/
    background-color: rgba(255, 255, 255, 0.1);
  }
  .avatar {
    border-radius: 2px;
    width: 30px;
    height: 30px;
    vertical-align: middle;
  }
  .name {
    display: inline-block;
    margin-left: 15px;
  }
  .el-badge {
    position: absolute;
    top: 21px;
    right: 10px;
  }
}
</style>
